>>It is almost insulting.
No it isn't, it is complicated, but I am reassured by the fact that you are struggling because it shows you are trying.
>>If you would read correctly the problem lies within how I lay out ALL data in my program:
I wouldn't worry about all the data in your program yet. When you get better at this game programming stuff you'll probably just ultimately scrap whatever you've created now for something more useful.
>>Question is, what happens if I have a cube, it isn't an MS3D Model, it is loaded normally...
Well, what I do is I have a data type that I have specified inside the renderer. For objects that are overly simple, i.e cubes lines and points, stuff like that, I just call them 'debug' items, because I don't really use them in practice, only for debugging. Here is how a line is represented in my code...it's really straightforward, and if you go back to the last post I made it follows the same general format for how I add a ms3d model to my renderer, in that I have the following:
-A simple data structure
-A function for adding the structure to my renderer
-A function for rendering the structure
The data structure for a line
Code:
struct DebugLineData
{
Vector3 Start;
Vector3 End;
Vector3 Color;
float Size;
};
A 'Vector3' is a three dimensional vector, a class that I wrote.
The code I use for adding a new line to the renderer
Code:
void AddDebugLineToRenderer(float StartX,float StartY,float StartZ,
float EndX,float EndY,float EndZ,
float ColorXRed,float ColorYGreen,float ColorZBlue,
float Width)
{
DebugLineData *pLine = new DebugLineData;
pLine->Start.x = StartX;
pLine->Start.y = StartY;
pLine->Start.z = StartZ;
pLine->End.x = EndX;
pLine->End.y = EndY;
pLine->End.z = EndZ;
pLine->Color.x = ColorXRed;
pLine->Color.y = ColorYGreen;
pLine->Color.z = ColorZBlue;
pLine->Size = Width;
this->mDebugLines.push_back(pLine);
}
The code to render a debug line
Code:
No lighting
No texturing
Coloring on
Depth test on (should never be changed)
*/
void GLRenderer::RenderAllDebugLines()
{
if(!mDebugLines.size())
{
return;
}
NT_GL(glDisable(GL_LIGHTING))
R_DisableAllTextures();
NT_GL(glEnable(GL_COLOR))
std::vector<DebugLineData*>::iterator ptr;
DebugLineData *pObject=0;
for(ptr = mDebugLines.begin(); ptr != mDebugLines.end(); ptr++)
{
pObject = (*ptr);
NT_GL(glLineWidth(pObject->Size))
NT_GL(glBegin(GL_LINES)) //FIXME: you can likely get this out of the loop
NT_GL(glColor3f(pObject->Color.x,pObject->Color.y,pObject->Color.z))
NT_GL(glVertex3f(pObject->Start.x,pObject->Start.y,pObject->Start.z))
NT_GL(glVertex3f(pObject->End.x,pObject->End.y,pObject->End.z))
NT_GL(glEnd())
}
}
Nevermind the NT_GL bit, it's a mechanism I found online if you are interested for writing your own implementation of openGL (I found it while looking for MESA GL, I saw that on the milkshape3d site...you can just remove the NT_GL() macro, leaving just the normal OpenGL function name).
But if I create a cube out of hard coding triangles, I can't use that file structure unless I define what index each triangle uses, which we all know now, that is impossible.
The only real solution I can think of is to use nothing but MS3D files and make all the models in my game use that setup or an m3d or something similar that is set up relatively the same..
I have found in my study that Bubba's data structures work well for a two dimensional game, where most polygons are hard coded. But for a three dimensional engine, where most of your (but maybe not all) data, is coming from a file type that is set up in a different way from what he specified.
Kudos to me for figuring that one out on my own! ..
I believe I have found my answer. I have to switch the way the data is stored so that it works for a 3-dimensional game, it is almost silly that I let this one slip past me.
In 3d - vertices make triangles make meshes
In 2d - vertices make it all
Hmmm, you are under the impression that you need some universal data type to represent everything. This is a farce.
Here are just some data structures in my renderer alone. I have a bunch. These aren't all of them, just the most basic.
Code:
/*
*********************************************************
DEBUG STUFF
*********************************************************
*/
struct DebugSphereData
{
Vector3 Position;
Vector3 Orientation;
Vector3 Color;
float Radius;
};
struct DebugLineData
{
Vector3 Start;
Vector3 End;
Vector3 Color;
float Size;
};
struct DebugBox
{
Vector3 Mins;
Vector3 Maxs;
Vector3 Pos;
};
struct DebugPoint
{
Vector3 Pos;
Vector3 Color;
float Size;
};
/*
Single texture
Lighting information allowed
*/
struct MS3DModelRenderData
{
Vector3 Position;
Vector3 Orientation;
CMS3D_MODEL *pModel;
};
/*
*********************************************************
ALPHA BLENDED STUFF
*********************************************************
*/
/*
Alpha blending information comes from the texture, not from glColor calls
*/
struct AlphaBlendedQuadRenderData
{
Vector3 Position;
Vector3 Width;
Vector3 Height;
float R,G,B;
int Texture; //Index into gpTextureManager
};